package com.itheima.admin.config;


import com.itheima.admin.interceptor.LoginInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author zhengbinghua
 * @since 2022/10/13 18:38
 */
@Slf4j
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                //.addPathPatterns("/**")
                .addPathPatterns(
                        "/category/**",
                        "/dish/**",
                        "/employee/**",
                        "/order/**",
                        "/setmeal/**",
                        "/doc.html" ,
                        "/webjars/**"

                )
                .excludePathPatterns("/employee/login", "/common/**");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        log.info("开始进行静态资源映射...");
        //addResourceLocations：指的是内部文件放置的目录
        //addResoureHandler指的是对外暴露的访问路径
        //swagger路径
        registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
    }
}
